#pragma once

#include <cmath>
#include <vector>

namespace solution_089
{

class Solution
{
public:
    std::vector<int> grayCode(int n)
    {
        std::vector<int> code;
        code.reserve(std::pow(2, n));
        code.push_back(0);
        for (int i = 0; i < n; ++i) {
            int k = code.size();
            for (int j = k - 1; j >= 0; --j)
                code.push_back(code.at(j) ^ (1 << i));
        }
        return code;
    }
};

}  /* namespace solution_089 */
